
var MenuList = new Pearlsen.BaseList({
	gridId:'menuGrid',
	advSearchId:'advSearchWin',
	module:'菜单',
	modulePath:'/pages/sysmgr/menu/',
	moduleName:'Menu',
	idProperty:'MENU_ID',
	nameProperty:'MENU_NAME',
	dataSetHandler:'MenuDataSetHandler',
	queryHandler:'MenuQueryHandler',
	//重写
	add:function(){
		var tree = Ext.getCmp("menuTree");
		var node = tree.getSelectionModel().getSelection();
		if( node && node.length > 0 ){
			var url = this.getAddUrl();
			url = url+"?parentId={0}";
			url = url.format(node[0].data['id']);
			var tabId = this.createTabId("add");
			parent.MainTab.addTab(tabId,"新增"+this.module,url);
		}else{
			Pearlsen.Utils.showInfoMsg('请先选中父级菜单');

		}
	},
	menuUp:function(){
		var me = MenuList;
		var record = me.getSelectedOne();
		if(record==null){
			return ;
		}
		var menuID =record.data[me.idProperty];
		
    	var dataSet = new DataSet(this.dataSetHandler,"_up_dataset");
    	dataSet.setHandlerMethod("menuUp");
    	dataSet.newRecord();
    	dataSet.setValue("menuID",menuID);
    	dataSet.execute(function(result){
    		if(result.getStatus()=="200"){
    			var node =Ext.getCmp("menuTree").getSelectionModel().getLastSelected();
    			me.loadGridByNodeId(node.data["id"]);
    			return;
    		}else{
    			Pearlsen.Utils.showErrorMsg(result.message);
    			return ;
    		}
    	});	
	},
	menuDown:function(){
		var me = MenuList;
		var record = me.getSelectedOne();
		if(record==null){
			return ;
		}
		var menuID =record.data[me.idProperty];
    	var dataSet = new DataSet(this.dataSetHandler,"_up_dataset");
    	dataSet.setHandlerMethod("menuDown");
    	dataSet.newRecord();
    	dataSet.setValue("menuID",menuID);
    	dataSet.execute(function(result){
    		if(result.getStatus()=="200"){
    			var node =Ext.getCmp("menuTree").getSelectionModel().getLastSelected();
    			me.loadGridByNodeId(node.data["id"]);
    			return;
    		}else{
    			Pearlsen.Utils.showErrorMsg(result.message);
    			return ;
    		}
    	});	
		
	},
	itemclick:function(tree,model){
		var me = MenuList;
		me.loadGridByNodeId(model.get("id"));
	},
	loadGridByNodeId:function(nodeId){
		var me = MenuList;
  		var store=me.getGrid().getStore();
  		store.setQuery(store.getBaseHandler(),store.getBaseMethod());
  		var condition=new Condition("id",nodeId);
  		store.setBaseConditions(condition);
  		store.load();
	},
	
	renderMenutype:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>菜单</span>";
                break;
            case "0":
                val = "<span style='color:blue;'>按钮</span>";
                break;
        }
        return val;
	},
	statusRender:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>启用</span>";
                break;
            case "0":
                val = "<span style='color:red;'>停用</span>";
                break;
        }
        return val;
	}
});




/*
MenuList = {
	grid:null,
	form:null,
	tree:null,
	getGrid:function(){
		var me = MenuList;
		if( me.grid ==null   ){
			me.grid = Ext.getCmp("menuGrid");
		}
		return me.grid;
	},
	getForm:function(){
		var me = MenuList;
		if( me.form ==null   ){
			me.form = Ext.getCmp("menuForm");
		}
		return me.form;
	},
	getTree:function(){
		var me = MenuList;
		if( me.tree ==null   ){
			me.tree = Ext.getCmp("menuTree");
		}
		return me.tree;
	},
	gridReload:function(){
		var me = MenuList;
		me.getGrid().getStore().load();
	},
	treeReload:function(){
		var me = MenuList;
		var node = me.getTree().getSelectionModel().getLastSelected();
		me.getTree().getStore().load({node:node});
	},
	itemclick:function(tree,model){
		var me = MenuList;
  		var store=me.getGrid().getStore();
  		var condition=new Condition("id",model.get("id"));
  		store.clearCondition();
  		store.addCondition(condition);
  		store.load();
	},
	renderMenutype:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>菜单</span>";
                break;
            case "0":
                val = "<span style='color:blue;'>按钮</span>";
                break;
        }
        return val;
	},
	statusRender:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>启用</span>";
                break;
            case "0":
                val = "<span style='color:red;'>停用</span>";
                break;
        }
        return val;
	},
	gridRowClick:function(grid,record,item,index,e,opt){
		var me = MenuList;
		var menuForm = me.getForm();
		menuForm.loadRecord(record);
	},
	add:function(){
		var me = MenuList;
		var menuForm = me.getForm();
		menuForm.reset();
		var tree = me.getTree();
		var record = tree.getSelectionModel().getLastSelected();
		Ext.getCmp("MENU_PARENT_ID").setValue(record.get("id"));
		Ext.getCmp('saveBtn').setDisabled(false);
	},
	edit:function(){
		Ext.getCmp('saveBtn').setDisabled(false);
	},
	del:function(){
		var me = MenuList;
		var menuGrid = me.getGrid();
		var record = menuGrid.getSelectionModel().getLastSelected();
     	if(!record){
     		Pearlsen.Utils.showInfoMsg('请选择一条数据!');
     		return false;
     	}
        Ext.MessageBox.confirm('Confirm', '确定要删除该数据吗?',function(btn){
        	if(btn=='yes'){
         	 	var ds=new DataSet('MenuDataSetHandler','SysMenuDataSet');
         	 	ds.setHandlerMethod("delete");
     			ds.addCondition("MENU_ID",record.get('MENU_ID'));
     			ds.execute();
     	  		me.treeReload();
     	  		me.gridReload();
     	  		me.getForm().reset();
         	 }
		});
	},
	refreshGrid:function(){
		var me = MenuList;
		me.gridReload();
	},
	save:function(){
		var me = MenuList;
		var menuForm = me.getForm();
		menuForm.submit();
	},
	afterSubmit:function(result){
		var me = MenuList;
		if( result.success ){
 	  		me.treeReload();
 	  		me.gridReload();
		}else{
			Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
		}
	}, 
	cancle:function(){
		var me = MenuList;
  		var grid=me.getGrid();
  		var menuForm = me.getForm();
		var recrods= grid.getSelectionModel().getSelection() || [];
		if( recrods.length > 0 ){
			menuForm.loadRecord(recrods[0]);
		}
		Ext.getCmp('saveBtn').setDisabled(true);
	}
};
*/
